<template>
    <div class="list" >
      <ul
        v-for="(arr,index) of cities"
        :key="index"
        @click="handleLetterClick"
        @touchstart="handleTouchStart"
        @touchsmove="handleTouchMove"
        @touchend="handleTouchEnd"
      >
        <li class="item">{{index}}</li>
      </ul>
    </div>
</template>

<script>
export default {
  name: 'CityAlphabet',
  props: {
    cities: Object
  },
  data () {
    return {
      touchStatus: false
    }
  },
  computed: {
    letters () {
      const letters = []
      for (let i in this.cities) { // for...in 循环获取的第一个参数是key, 区别于for...of
        letters.push(i)
      }
      return letters
    }
  },
  methods: {
    handleLetterClick (e) {
      this.$emit('change', e.target.innerHTML)
    },
    handleTouchStart () {
      this.touchStatus = true
    },
    handleTouchMove () {
      if (this.touchStatus) {

      }
    },
    handleTouchEnd () {
      this.touchStatus = false
    }

  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  .list
    display flex
    flex-flow column nowrap
    justify-content  center
    align-items center
    position absolute
    top 1.58rem
    right 0
    bottom 0
    width .4rem
    .item
      color $bgColor
      font-size .30rem
      line-height .4rem
      touch-action none
      /*无法被动侦听事件preventDefault，是新版本chrome 浏览器报错。*/
</style>
